<?php defined('IN_LK') or die('Access Denied');
lk::lo('model', '', 0);
class comment_model extends model
{
	public function __construct()
	{
		$this->tablename = 'comment';
		parent::__construct();
	}
	
	/**
	 * 评论设置 发布间隔与禁止
	 * @param int $id 信息id
	 * @return boolean 
	 */
	public function comment_check($id)
	{
		$uid  = $_SESSION['_userid'];
		$last = $this->get_one('dtime', "`userid`='$uid' AND `cid`='$id'", '`dtime` DESC');
		if(!$last)
		{
			return true;
		}
		return ((TIME - $last['dtime'])>= COMMENT_TIMEOUT) ? true : false;
	}
	
	/**
	 * 取平均好评度 每颗星20分
	 * @param int $id 信息id
	 * @return int 新分数 
	 */
	public function feedback($id)
	{
		$rs = $this->get('star', "`cid`='$id' AND `disable`='0'");
		$total = count($rs);
		$stars = 0;
		if($total)
		{
			foreach($rs as $v)
			{
				$stars += $v['star'];
			}
			$f = (int)round($stars * 20 / $total);
			return $f;
		}
		return 100;
	}
}